package com.jly.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jly.Util.Constants;
import com.jly.Util.ResponseData;
import com.jly.Util.util;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
@RequestMapping(value = "/base",method = RequestMethod.POST)
public class BaseController {

    /**
     * 添加店铺
     * @param id
     * @return
     */
    @RequestMapping("/addStore")
    public Object addStore(String id){
        ResponseData result = new ResponseData();
        try {
            JSONObject json = JSON.parseObject(id);

        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(Constants.Fail_400);
            result.setMsg(e.getMessage());
        }
        return result;
    }

    /**
     * 修改单据状态
     * @param id
     * @return
     */
    @RequestMapping("/updateIvt")
    public Object updateIvt(HttpServletRequest request,String id){
        ResponseData result = new ResponseData();
        try {
            JSONObject json = JSON.parseObject(id);
            JSONArray array = new JSONArray();
            json.put("tb", "IvtFather");
            JSONObject obj = json.getJSONObject("obj");
            obj.put("ity_audituid",request.getSession().getAttribute("user_id"));
            obj.put("ity_operatTime2", new Date().getTime());
            json.put("obj", obj);
            array.add(json);
            JSONObject jsons = new JSONObject();
            jsons.put("array", array);
            json = util.sendPost(Constants.URL + "/android/updateIvt.do", json);
            result = JSON.toJavaObject(json, ResponseData.class);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(Constants.Fail_400);
            result.setMsg(e.getMessage());
        }
        return result;
    }

}
